package com.antifly.common.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.antifly.common.dao.SysGlobalAttachmentDao;
import com.antifly.common.dao.mapper.SysGlobalAttachmentMapper;
import com.antifly.common.pojo.entity.SysGlobalAttachmentDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 附件表(SysGlobalAttachment)Dao接口实现
 *
 * @author makejava
 * @date 2023-04-25
 */
@Component
public class SysGlobalAttachmentDaoImpl extends ServiceImpl<SysGlobalAttachmentMapper, SysGlobalAttachmentDO> implements SysGlobalAttachmentDao {

    @Autowired
    private SysGlobalAttachmentMapper sysGlobalAttachmentMapper;

    /**
     * 分页查询附件表信息
     *
     * @param key      搜索关键字
     * @param pageNum  当前页码
     * @param pageSize 每页展示数 当值为-1时默认展示全部
     * @return
     */
    @Override
    public Page<SysGlobalAttachmentDO> selectSysGlobalAttachmentList(String key, Integer pageNum, Integer pageSize) {
        Page<SysGlobalAttachmentDO> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SysGlobalAttachmentDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(SysGlobalAttachmentDO::getCreatedTime);
        return sysGlobalAttachmentMapper.selectPage(page, lambdaQueryWrapper);
    }

    @Override
    public List<SysGlobalAttachmentDO> selectSysGlobalAttachmentList() {
        LambdaQueryWrapper<SysGlobalAttachmentDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(SysGlobalAttachmentDO::getCreatedTime);
        return sysGlobalAttachmentMapper.selectList(lambdaQueryWrapper);
    }

    /**
     * 查询所有附件表信息
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> selectMaps() {
        return sysGlobalAttachmentMapper.selectMaps(null);
    }

    /**
     * 根据id查询附件表信息
     *
     * @param id 主键ID
     * @return
     */
    @Override
    public SysGlobalAttachmentDO selectSysGlobalAttachmentById(String id) {
        return sysGlobalAttachmentMapper.selectById(id);
    }

    @Override
    public String insertSysGlobalAttachment(SysGlobalAttachmentDO sysGlobalAttachmentDO) {
        sysGlobalAttachmentMapper.insert(sysGlobalAttachmentDO);
        return sysGlobalAttachmentDO.getId();
    }

    @Override
    public Boolean updateSysGlobalAttachment(SysGlobalAttachmentDO sysGlobalAttachmentDO) {
        int rows = sysGlobalAttachmentMapper.updateById(sysGlobalAttachmentDO);
        return rows > 0;
    }

    @Override
    public Boolean deleteSysGlobalAttachment(String sysGlobalAttachmentId) {
        int rows = sysGlobalAttachmentMapper.deleteById(sysGlobalAttachmentId);
        return rows > 0;
    }

}